<!DOCTYPE html>
<html class="ui-page-login">

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title></title>
    <script src="__PUBLIC__/js/jquery.min.js"></script>
    <script src="__PUBLIC__/home/plugins/layer/layer.js"></script>
    <script src="__PUBLIC__/mui/js/mui.min.js"></script>
    <script src="__PUBLIC__/mui/js/mui.picker.min.js"></script>
    <script src="__PUBLIC__/js/angular.js"></script>
    <script src="__PUBLIC__/common.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/mui/css/mui.css">
    <link rel="stylesheet" href="__PUBLIC__/mui/css/mui.picker.min.css">
    <style>
        #member-login {
            display: none;
        }

        .area {
            margin: 20px auto 0px auto;
        }

        .mui-input-group {
            margin-top: 10px;
        }

        .mui-input-group:first-child {
            margin-top: 20px;
        }

        .mui-input-group label {
            width: 38%;
        }

        .mui-input-row label ~ input,
        .mui-input-row label ~ select,
        .mui-input-row label ~ textarea {
            width: 62%;
        }

        .content {
            width: 60%;
            float: right;
            line-height: 40px;
            height: 40px;
            text-indent: 2em;
            font-size: 16px;
            text-align: right;
            padding-right: 1em;

        }

        .mui-checkbox input[type=checkbox],
        .mui-radio input[type=radio] {
            top: 6px;
        }

        .mui-content-padded {
            margin-top: 25px;
        }

        .mui-btn {
            padding: 10px;
        }

        .link-area {
            display: block;
            margin-top: 25px;
            text-align: center;
        }

        .spliter {
            color: #bbb;
            padding: 0px 8px;
        }

        .oauth-area {
            position: absolute;
            bottom: 20px;
            left: 0px;
            text-align: center;
            width: 100%;
            padding: 0px;
            margin: 0px;
        }

        .oauth-area .oauth-btn {
            display: inline-block;
            width: 50px;
            height: 50px;
            background-size: 30px 30px;
            background-position: center center;
            background-repeat: no-repeat;
            margin: 0px 20px;
            /*-webkit-filter: grayscale(100%); */
            border: solid 1px #ddd;
            border-radius: 25px;
        }

        .oauth-area .oauth-btn:active {
            border: solid 1px #aaa;
        }

        .oauth-area .oauth-btn.disabled {
            background-color: #ddd;
        }

        .login-active {
            background: #f3363a;
            color: white;
        }

        .fanyong-title p {
            line-height: 40px;
            font-size: 16px;
            margin: 0;
            color: #111111;
        }

        .mui-input-row .mui-input-clear::-webkit-input-placeholder {
            text-align: center;
            font-size: 14px;
        }

        #user-login .mui-input-row .time {
            width: 65%;
            color: black;
        }

        #user-login .mui-input-row .status {
            width: 35%;
            font-size: 14px;
            font-weight: bold;
            font-family: "Microsoft YaHei UI Light";

        }

        .mui-input-group .mui-input-row:nth-child(1) {
            border-top: 1px solid #c8c7cc;
        }

        .mui-input-group .mui-input-row:after {
            left: 0;
        }

        .mui-input-group .mui-input-row:nth-child(1):after {
            background: none;
        }

        .mui-input-group .mui-input-row:last-child:after {
            background: none;
        }

        #user-login .mui-input-group {
            margin-top: 0;
        }

        #withdraw {
            color: white;
            font-size: 16px;
            line-height: 44px;
            margin: 0;
            padding: 0;
            height: 44px;
        }

        #user-login .mui-input-group {
            background: white;
        }

        .login-tab div {
            border: 1px solid white;
            box-sizing: border-box;
        }

        .cart-total {
            background: white;
        }

        .money-all {
            width: 70%;
            float: left;
            line-height: 50px;
            height: 50px;
            font-size: 16px;
            color: #333333;
            text-indent: 1em;
        }

        .go-deal {
            background: #f2373b;
            color: white;
            text-align: center;
            font-size: 18px;
            font-weight: bold;
        }

        #money {
            color: #f2373b;
        }

        .btn {
            font-size: 14px;
            text-align: center;
        }

        .daili::-webkit-input-placeholder {
            font-size: 15px;
        }

        .mui-segmented-control .mui-control-item.mui-active {
            color: #ff6769;
            background: #fff;
        }

        .mui-segmented-control .mui-control-item {
            border-left: 1px solid #EDEDED;
            background: #fff;
        }

        .mui-segmented-control .mui-control-item {
            color: #666666;
        }

    </style>
    <link rel="stylesheet" href="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.css">
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.js"></script>
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/local/zh-CN.js"></script>

</head>

<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
<header class="mui-bar mui-bar-nav" style="background:#f3363a;">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white"></a>
    <h1 class="mui-title login-item" style="color: white;left: 70px;right: 70px">
        <div class="login-tab" style="">
            <div name="type" id="chu" class="mui-btn mui-col-xs-6 login-active"
                 style="float: left;border-radius: 0;padding: 5px 7px 5px;" ng-click="find()">
                <input type="hidden" name="type" value="1">我的出款
            </div>
            <div name="type" id="shou" class="mui-btn mui-col-xs-6 "
                 style="border-radius: 0;padding: 5px 7px 5px;" ng-click="find()">
                <input type="hidden" name="type" value="2">我的收款
            </div>
        </div>
    </h1>
    <div class=" mui-icon  mui-pull-right" style="color: white;font-size: 16px;line-height: 44px;margin: 0;padding: 0"
         ng-click="find()" id="find">查询
    </div>
</header>
<div class="mui-content" id="user-login">

    <form class="mui-input-group" method="post" action="" style="margin-top: 0"
          data-validator-option="{stopOnError:false, timely:true,theme:'layer'}">
        <div style="padding: 2px 2px;">
            <div id="segmentedControl" class="mui-segmented-control">
                <a id="st0" class="mui-control-item mui-active">
                    全部
                </a>
                <a id="st1" class="mui-control-item">
                    未转账
                </a>
                <a id="st2" class="mui-control-item">
                    已转账
                </a>
                <a id="st3" class="mui-control-item">
                    已完成
                </a>
            </div>
        </div>
        <div class="mui-input-row" style="margin-top: 5px">
            <input name='begin_time' type="text" data-options='{"type":"date","beginYear":2010,"endYear":2022}'
                   id="begin" class=" btn mui-input-clear mui-input" readonly placeholder="选择查询起始时间"
                   style="width: 50%;float: left">
            <input name='end_time' type="text" id="end" class=" btn mui-input-clear mui-input" readonly
                   placeholder="选择查询结束时间" style="width: 50%;float: right">
        </div>
        <div class="mui-input-row fanyong-title">
            <input name="chanchu" class="mui-col-xs-4 daili" style="display: inline-block;text-align: right"
                   placeholder="产出代理" id="chanchu">
            <p class="mui-col-xs-4" style="display: inline-block;text-align: center;color: #53b6f2;font-size: 20px">
                &</p>
            <input name="shoukuan" class="mui-col-xs-3 daili" style="display: inline-block;text-align: left"
                   placeholder="收款代理" id="shoukuan" ng-model="skdl">
            <input type="hidden" value="0" ng-model="statustype" name="statustype">
        </div>
    </form>
    <div id="list">
        <div class="mui-input-group" style="margin-top: 3px" ng-repeat="x in message">
            <div class="mui-input-row" style="background:#f6f6f6">
                <label class="time">{{x.createtime}}</label>
                <div class="content status" style="color: #f2373b">
                    {{x.statusname}}
                </div>
            </div>
            <div class="mui-input-row">
                <label>产出代理账号</label>
                <div class="content">
                    {{x.source}}
                </div>
            </div>
            <div class="mui-input-row">
                <label>
                    <span ng-show="status==1">收款</span><span ng-show="status==2">出款</span>代理账号</label>
                <div class="content" ng-show="status==1">
                    {{x.account}}
                </div>
                <div class="content" ng-show="status==2">
                    {{x.arrears}}
                </div>
            </div>
            <div class="mui-input-row">
                <label>金额</label>
                <div class="content">
                    {{x.money}}
                </div>
            </div>
            <div class="mui-input-row" style="background:white" ng-show="x.status == 1 &&  typ==1">
                <button type="button"
                        style="margin-right: 1em;text-align: center;padding: 5px 10px;height: 30px;margin-top: 5px;border-radius: 0"
                        class="mui-btn mui-btn-danger mui-btn-outlined" ng-click="mekesure(x.id)">转账
                </button>
            </div>
            <div class="mui-input-row" style="background:white" ng-show="x.status == 2 && typ==2">
                <button type="button"
                        style="margin-right: 1em;text-align: center;padding: 5px 10px;height: 30px;margin-top: 5px;border-radius: 0"
                        class="mui-btn mui-btn-danger mui-btn-outlined" ng-click="mekesure2(x.id)">确认
                </button>
            </div>
        </div>
        <div style="height: 60px"></div>
        <div class="cart-total " style="position: fixed;bottom: 50px;width: 100%">
            <ul class="mui-table-view">
                <li class=" mui-media " style="width: 100%">
                    <div class="mui-media-body  do-cart" style="display: flex;height: 60px">
                        <p class="money-all" style="width: 70%;height: 60px;line-height: 60px">合计:￥<span id="money">{{total}}</span>
                        </p>
                        <p class="go-deal ungo-deal" id="go-deal" style="width: 30%;height: 60px;line-height: 60px"
                           ng-click="sub()" ng-show="typ==1 && slctyp==1 && message != ''">转账</p>
                        <p class="go-deal ungo-deal" style="width: 30%;height: 60px;line-height: 60px" ng-click="sub2()"
                           ng-show="typ==2 && slctyp==2 && message != ''">确认</p>
                    </div>
                </li>

            </ul>
        </div>
    </div>
</div>
<include file="./Application/Home/View/pub/agentfoot.html" name="m"/>
<script>
    $(function () {
        $('#hidtype').val('1');
        //$('#find').click();
    });

    (function ($) {
        $.init();
        var result = $('#result')[0];
        var btns = $('#begin');
        btns.each(function (i, btn) {
            btn.addEventListener('tap', function () {
                var optionsJson = this.getAttribute('data-options') || '{}';
                var options = JSON.parse(optionsJson);
                var id = this.getAttribute('id');
                /*
                 * 首次显示时实例化组件
                 * 示例为了简洁，将 options 放在了按钮的 dom 上
                 * 也可以直接通过代码声明 optinos 用于实例化 DtPicker
                 */
                var picker = new $.DtPicker(options);
                picker.show(function (rs) {
                    document.getElementById("begin").value = rs.text
                    picker.dispose();
                });
            }, false);
        });

        var btns = $('#end');
        btns.each(function (i, btn) {
            btn.addEventListener('tap', function () {
                var optionsJson = this.getAttribute('data-options') || '{}';
                var options = JSON.parse(optionsJson);
                var id = this.getAttribute('id');
                /*
                 * 首次显示时实例化组件
                 * 示例为了简洁，将 options 放在了按钮的 dom 上
                 * 也可以直接通过代码声明 optinos 用于实例化 DtPicker
                 */
                var picker = new $.DtPicker(options);
                picker.show(function (rs) {
                    document.getElementById("end").value = rs.text
                    picker.dispose();
                });
            }, false);
        });

    })(mui);

    //用户登录
    var app = getApp('myApp', []);
    app.controller('Ctrl', function ($scope, $http) {
        document.getElementById('st0').addEventListener('tap', function () {
            $scope.getbytype(0);
        });
        document.getElementById('st1').addEventListener('tap', function () {
            $scope.getbytype(1);
        });
        document.getElementById('st2').addEventListener('tap', function () {
            $scope.getbytype(2);
        });
        document.getElementById('st3').addEventListener('tap', function () {
            $scope.getbytype(3);
        });

        // 当前页数
        $scope.currentPage = 0;
        // 加载完毕标志
        $scope.endflg = 0;
        // 防止重复加载
        $scope.busy = false;
        // 存放数据
        $scope.message = [];
        // 请求数据方法
        $scope.loadMore = function () {
            $scope.slctyp = $('input[name=statustype]').val();
            $scope.skdl = $("#shoukuan").val();
            $scope.typeid = $(".login-tab").find(".login-active").find("input[type='hidden']").val();
            $scope.begin_time = $('#begin').val();
            $scope.end_time = $('#end').val();
            $scope.chanchu = $('#chanchu').val();
            $scope.shoukuan = $('#shoukuan').val();
            //console.log($scope.currentPage)
            if ($scope.endflg == 0) {
                if ($scope.busy) {
                    return false;
                }
                $scope.busy = true;
                $http({
                    method: 'POST',
                    data: $scope,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    transformRequest: function (obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    },
                    url: "/index.php/Home/Agen/myallbrokerage"
                }).then(function successCallback(response) {
                    //console.log(response.data.data)
                    $scope.busy = false;
                    if (response.data.data.skck != '' && response.data.data.skck != null) {
                        if ($scope.currentPage > 0) {
                            layer.msg("正在加载...", {time: 500});
                        }
                    } else {
                        layer.msg("已加载完毕", {time: 500});
                        $scope.endflg = 1;
                        return false;
                    }
                    $scope.currentPage++;
                    if (response.data.code == -1) {
                        layer.msg(response.data.msg, {time: 1500})
                    } else {
                        $scope.status = response.data.data.type;
                        //$scope.idlist = response.data.data.idlist;
                        $scope.typ = response.data.data.type;
                        $scope.skdl = response.data.data.dl;
                        // 组织数据
                        for (var i in response.data.data.skck) {
                            $scope.message.push(response.data.data.skck[i]);
                        }
                        //统计总价
                        $scope.total = 0;
                        for (var x in $scope.message) {
                            if($scope.typeid == 1){
                                if($scope.message[x].status == 1){
                                    $scope.total = $scope.total*1 + $scope.message[x].money*1;
                                }
                            } else if($scope.typeid == 2){
                                if($scope.message[x].status == 2){
                                    $scope.total = $scope.total*1 + $scope.message[x].money*1;
                                }
                            }
                        }
                    }
                }, function errorCallback(response) {
                    errorHandle(response);
                });
            } else {
                layer.msg("已加载完毕", {time: 500});
            }
        };
        // 进页面先加载一次数据
        $scope.loadMore();

        // 页面可视区域高度
        var winH = $(window).height();
        var scrollHandler = function () {
            // 页面高度
            var pageH = $(document.body).height();
            // 滚动条top
            var scrollT = $(window).scrollTop();
            var toend = (pageH - winH - scrollT) / winH;
            if (toend == 0) {
                $scope.loadMore();
            }
        }
        // 定义鼠标滚动事件
        $(window).scroll(scrollHandler);

        // 根据tab获取数据
        $scope.getbystatus = function (status) {
            $scope.status = status;
            // 当前页数
            $scope.currentPage = 0;
            // 加载完毕标志
            $scope.endflg = 0;
            // 防止重复加载
            $scope.busy = false;
            // 存放数据
            $scope.message = [];
            $scope.loadMore();
        }

        //隐藏域传值
        $scope.getbytype = function (value) {
            $('input[name=statustype]').val(value);
            $scope.find();
        }

        //查询
        $scope.find = function () {
            // 当前页数
            $scope.currentPage = 0;
            // 加载完毕标志
            $scope.endflg = 0;
            // 防止重复加载
            $scope.busy = false;
            // 存放数据
            $scope.message = [];
            $scope.loadMore();
        }

        //转账
        $scope.mekesure = function (id) {
            var btnArray = ['否', '是'];
            mui.confirm('', '是否确认', btnArray, function (e) {
                if (e.index == 1) {
                    $http({
                        method: 'GET',
//                        cache:false,
                        params: {id: id},
                        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                        transformRequest: function (obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Agen/verifyBrokerage"
                    }).then(function successCallback(response) {
                        if(response.data.code == -1){
                            layer.msg(response.data.msg, {time: 1000});
                        }
                        successHandle(response, function () {
                            layer.msg(response.data.msg, {time: 1000});
                            setTimeout(function () {
                                $scope.find();
                            },1000)
                        });
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }
            })
        }

        //完成确认
        $scope.mekesure2 = function (id) {
            var btnArray = ['否', '是'];
            mui.confirm('', '是否确认', btnArray, function (e) {
                if (e.index == 1) {
                    $http({
                        method: 'GET',
//                        cache:false,
                        params: {id: id},
                        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                        transformRequest: function (obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Agen/verifyBrokerage2"
                    }).then(function successCallback(response) {
                        if(response.data.code == -1){
                            layer.msg(response.data.msg, {time: 1000});
                        }
                        successHandle(response, function () {
                            layer.msg(response.data.msg, {time: 1000});
                            setTimeout(function () {
                                $scope.find();
                            },1000)
                        });
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }
            })
        }

        //全部转账
        $scope.sub = function () {
            $scope.find();
            var btnArray = ['否', '是'];
            mui.confirm('', '是否确认', btnArray, function (e) {
                if (e.index == 1) {
                    var data = new Array();
                    var i = 0;
                    //console.log($scope.message);
                    var acc = '';
                    for (var c in $scope.message) {
                        if(acc == ''){
                            acc = $scope.message[c].account;
                        } else {
                            if(acc != $scope.message[c].account){
                                layer.msg("请查询后再转账", {time: 1000})
                                return;
                            }
                        }
                        data[i] = $scope.message[c].id;
                        i++;
                    }
                    var skdl = $scope.skdl
                    //console.log(data);
                    $http({
                        method: 'POST',
                        data: {'idlist': data, 'skdl': skdl},
                        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                        transformRequest: function (obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Agen/allVerify"
                    }).then(function successCallback(response) {
                        //console.log(response.data);
                        if(response.data.code == -1){
                            layer.msg(response.data.msg, {time: 1000});
                        }
                        successHandle(response, function () {
                            layer.msg(response.data.msg, {time: 1000});
                            setTimeout(function () {
                                $scope.find();
                            },1000)
                        });
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }
            })
        }

        //全部确认
        $scope.sub2 = function () {
            $scope.find();
            var btnArray = ['否', '是'];
            mui.confirm('', '是否确认', btnArray, function (e) {
                if (e.index == 1) {
                    var data = new Array();
                    var i = 0;
                    //console.log($scope.message);
                    var acc = '';
                    for (var c in $scope.message) {
                        if(acc == ''){
                            acc = $scope.message[c].account;
                        } else {
                            if(acc != $scope.message[c].account){
                                layer.msg("请查询后再转账", {time: 1000})
                                return;
                            }
                        }
                        data[i] = $scope.message[c].id;
                        i++;
                    }
                    var skdl = $scope.skdl
                    //console.log(data);
                    $http({
                        method: 'POST',
                        data: {'idlist': data, 'skdl': skdl},
                        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                        transformRequest: function (obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Agen/allVerify2"
                    }).then(function successCallback(response) {
                        if(response.data.code == -1){
                            layer.msg(response.data.msg, {time: 1000});
                        }
                        successHandle(response, function () {
                            layer.msg(response.data.msg, {time: 1000});
                            setTimeout(function () {
                                $scope.find();
                            },1000)
                        });
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }
            })
        }
    });

    /*代理登录*/
    $(".login-tab>div").click(function () {
        $(this).siblings("div").removeClass("login-active");
        $(this).addClass("login-active");
        var typeid = $(".login-tab").find(".login-active").find("input[type='hidden']").val();
        if (typeid == 1) {
            $("#shoukuan").attr("placeholder", "收款代理")
        } else {
            $("#shoukuan").attr("placeholder", "出款代理")
            /*   $(".income").html('出款')*/

        }
    })


</script>
</body>
</html>
